package chapter08.chapter8_7_ChangeUnidirectionalAssociationToBidirectional.ver03;

import java.util.Set;

public class Order {

    private Set<Customer> customers;

    // 一个订单可以对应多个客户，因此要将setCustomer更名为addCustomer，将customer字段更改为Set类型
    public void addCustomer(Customer customer) {
        customer.friendOrders().add(this);
        customers.add(customer);
    }

    public void removeCustomer(Customer customer) {
        // 先将Customer中的该订单移除，再从Order中移除该Customer
        customer.friendOrders().remove(this);
        customers.remove(customer);
    }

}
